package com.yidu.DailyFinalTreatment.mapper;

import com.yidu.BusinessParameters.entity.Trade;
import com.yidu.DailyFinalTreatment.entity.AssetValuationMjoinS;
import com.yidu.StockControl.entity.CashInventory;
import com.yidu.StockControl.entity.SecurityInventory;
import com.yidu.TAManagement.entity.TABusiness;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Repository;

import java.util.List;
import java.util.Map;

@Repository
public interface AsseMapper {
//    @Select("SELECT * FROM securityInventors AS s JOIN market AS m ON s.securityId=m.securityId")
//    public void selectAsse(HashMap hashMap);s.businessStatu,

    @Select("SELECT s.securityId,\n" +
            "ROUND((IFNULL(s.securityNum,0)*IFNULL(m.endMoney,0)-securityMoney),2) AS tootaIPrice,st.securityName FROM \n" +
            "(SELECT * FROM securityInventors WHERE securityInventorsTime=#{dateTime} AND fundId='000899') s \n" +
            "JOIN (SELECT * FROM market WHERE inputDate=#{dateTime}) m \n" +
            "ON s.securityId=m.securityId\n" +
            "JOIN \n" +
            "(SELECT * FROM  SECURITY)st ON st.securityId=m.securityId")
    List<AssetValuationMjoinS>  selectStockarket(Map map);

    //证券
    @Delete(" delete from  SecurityInventory  where fundId=#{fundId} and securityInventoryTime=#{securityInventoryTime} \n" +
            " and businessStatu= #{businessStatu} and securityId=#{securityId}")
    int delectSecurityAccrualStock(SecurityInventory securityInventory);

    //交易数据
    @Select("SELECT t.*,s.securityName FROM trade t\n" +
            "JOIN\n" +
            "(SELECT * FROM  SECURITY) s ON t.securityId=s.securityId\n" +
            " WHERE STR_TO_DATE(#{tradeDate},'%Y-%m-%d') < STR_TO_DATE(settleDate,'%Y-%m-%d')\n" +
            " AND  STR_TO_DATE(#{tradeDate},'%Y-%m-%d') >= STR_TO_DATE(tradeDate,'%Y-%m-%d')")
    List<Trade> selectTransactionData(Map map);

    //Ta
    @Select("select * from TABusiness where STR_TO_DATE(#{businessTime},'%Y-%m-%d') < STR_TO_DATE(businessEndTime,'%Y-%m-%d') \n" +
            " and  STR_TO_DATE(#{businessTime},'%Y-%m-%d') >= STR_TO_DATE(businessTime,'%Y-%m-%d')")
    List<TABusiness> selectTa(Map map);

    //现金
    @Delete("delete from cashInventory where cashId=#{cashId} and cashInventoryTime=#{cashInventoryTime}\n" +
            " and businessStatu=#{businessStatu}")
    int delectCashAccrualStock(CashInventory cashInventory);
}
